<?php
namespace common\modules\mapp;

class ModuleInfo extends \common\core\modularity\ModuleInfo
{

    public function init()
    {
        parent::init();

        $this->id = "mapp";
        $this->name = "移动应用";
        $this->description = '移动应用管理模块，包括移动应用更新，移动应用错误日志';
        $this->version = '1.0.0';
        $this->icon = '<i class="fa fa-tablet"></i>';
        $this->has_backend = true;
        $this->has_frontend = false;
        $this->has_api = false;

        $this->is_system = false;

        $this->requireModules = 'user';
    }
    
    public function install()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }
        /* APP版本升级表 */
        $this->createTable('{{%mapp_version_upgrade}}', [
            'id' => $this->primaryKey(),
            'app_id' => $this->smallInteger(4)
            ->defaultValue(0), // 客户端设备id：1 安卓手机 2 苹果手机
            'version_major' => $this->smallInteger(4)
            ->defaultValue(0),
            'version_mini' => $this->integer(8)
            ->defaultValue(0),
            'version_code' => $this->string(10),
            'download_url' => $this->string(255),
            'upgrade_type' => $this->smallInteger(2), // 是否升级： 0 不升级 1 升级 2 强制升级
            'upgrade_hint' => $this->string(255), // 是否升级： 0 不升级 1 升级 2 强制升级
            'status' => $this->smallInteger(2),
            'created_by' => $this->integer(),
            'created_at' => $this->integer()
        ], $tableOptions);
    
        /* APP错误日志表 */
        $this->createTable('{{%mapp_error_log}}', [
            'id' => $this->primaryKey(),
            'app_id' => $this->smallInteger(4)
            ->defaultValue(0), // 客户端设备id：1 安卓手机 2 苹果手机
            'device_id' => $this->string(),
            'version_major' => $this->smallInteger(4)
            ->defaultValue(0),
            'version_mini' => $this->smallInteger(4)
            ->defaultValue(0),
            'title' => $this->string(),
            'message' => $this->text(),
            'created_at' => $this->integer()
        ], $tableOptions);
    }
    
    public function uninstall()
    {
        $this->dropTable('{{%mapp_error_log}}');
        $this->dropTable('{{%mapp_version_upgrade}}');
    }
}